using System;
using ServiceFacade;

namespace ServiceManager
{
    public class Service : IService
    {
        private string _ServiceName;
        private ServiceStatus _ServiceStatus;

        #region Properties
		
        public string ServiceName
        {
            get { return this._ServiceName; }
        }

        public ServiceStatus ServiceStatus
        {
            get { return this._ServiceStatus; }
            set { this._ServiceStatus = value; }
        }


	    #endregion        
      
        #region Public Methods
        public Service(string name, ServiceStatus status)
        {
            this._ServiceName = name;
            this._ServiceStatus = status;
        }

        public void ExecuteCommand(CommandType command, IServiceFacade serviceFacade)
        {
            if (command == CommandType.StartService)
            {
                if (this._ServiceStatus == ServiceStatus.Started)
                {
                    throw new InvalidStatusException("Cannot start a service that has already been started.");
                }

                serviceFacade.startService(this._ServiceName);
                this._ServiceStatus = ServiceStatus.Started;
            }
            else if (command == CommandType.StopService)
            {
                if (this._ServiceStatus == ServiceStatus.Stopped)
                {
                    throw new InvalidStatusException("Cannot stop a service that has already been stopped.");
                }

                serviceFacade.stopService(this._ServiceName);
                this._ServiceStatus = ServiceStatus.Stopped;
            }
        }
        #endregion
    }
}
